<?php

use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;

/**
 * 数据迁移方式完成，中成药添加到数据库
 *
 * Class AddChinesePatentMedicine
 */
class AddChinesePatentMedicine extends Migration
{
    protected $drug_names = [
        '芪蛭降糖胶囊', '天麦消渴片', '参芪降糖胶囊', '降糖通脉宁胶囊', '天芪降糖胶囊', '茵栀黄颗粒', '白芍总苷胶囊',
        '糖微康胶囊', '桂枝茯苓胶囊', '雷公藤胶囊', '津力达颗粒'
    ];

    /**
     * Run the migrations.
     * @return void
     */
    public function up()
    {
        $data = [];
        $time = Carbon::now()->toDateTimeString();

        foreach ($this->drug_names as $name) {
            $data[] = [
                'name'       => $name,
                'doctor_id'  => 277,
                'type'       => 3,
                'created_at' => $time,
                'updated_at' => $time,
            ];
        }

        DB::table('st_drug_dictionary')->insert($data);
    }

    /**
     * Reverse the migrations.
     * @return void
     */
    public function down()
    {
        DB::table('st_drug_dictionary')->whereIn('name', $this->drug_names)
          ->where('type', 3)->delete();
    }
}
